<template>
	<view class="app_Cont">
		<view class="showCont" v-if="showCont">
			<view class="formCont">
				<view class="formTitle">个人信息</view>
				<view class="headImgCont">
					<avatar 
						selWidth="400upx" selHeight="400upx" stretch="shortSel" :inner="true" @upload="myUpload" :avatarSrc="formData.head_img"
						>
					</avatar>
				</view>
				<view class="formItem">
					<view class="inputName">
					    <view class="inputNameText">您的昵称</view>
				    </view>
					<view class="inputValue">
						<input maxlength="10" v-model="formData.nick_name" placeholder="请输入对您的称呼"  />
					</view>
				</view>
				<view class="formItem">
					<view class="inputName">
					    <view class="inputNameText">您的性别</view>
				    </view>
					<view class="inputOut">
						<view class="inputMask" @click="showSex = true"></view>
						<input
						  v-model="formData.user_sex"
						  placeholder="请选择您的性别"
						/>
					</view>
					<view
						@click="showSex = true"
						class="iconfont icon-xiala"
					></view>
				</view>
			</view>
			<view class="saveBtn" @click="saveFn">保存设置</view>
			<u-notify ref="uNotify" ></u-notify>
			<u-toast ref="uToast"></u-toast>
			<subLoad v-if="showSub"></subLoad>
			<u-picker :show="showSex" @confirm="sexSureFn" @cancel="showSex = false" @close="showSex = false" :closeOnClickOverlay="true" :columns="sexArr"></u-picker>
		</view>
		<load v-if="!showCont"></load>
	</view>
</template>

<script>
	import ruleCheck from '@/utils/ruleCheck.js'
	import api from '@/http/api.js'
	import load from '@/components/load.vue'
	import upfile from '@/utils/upfile.js'
	import avatar from "@/components/yq-avatar/yq-avatar.vue";
	import subLoad from '@/components/sub.vue'
	export default {
		components:{subLoad,avatar,load},
		data() {
			return {
				showSub:false,
				showCont:false,
				formData: {
					head_img:'',
					nick_name:'',
					user_sex:'',
				},
				showSex:false,
				sexArr:[
					['男生','女生']
				],
				
			};
		},
		methods:{
			getData(){
				api.getRequst({},'/api/My').then((res)=>{
					if(res.code==1){
						this.formData = {
							head_img:res.data.user.head_img,
							nick_name:res.data.user.nick_name,
							user_sex:res.data.user.user_sex==1?'男生':'女生',
						}
					}
					this.showCont = true
				})
			},
			
			myUpload(rsp) {
				// console.log(rsp.avatar)
				this.showSub = true
				console.log(rsp.path)
				upfile.upfile(rsp.path).then((res)=>{
					this.formData.head_img = res
					this.showSub = false
				})
			},
			sexSureFn(data){
				this.formData.user_sex  = data.value[0]
				this.showSex = false
			},
			saveFn(){
				let data = this.formData
				let tipData = {
					bgColor: '#e47470',
					message: '',
				}
				if(!data.nick_name){
					tipData.message = '请输入您的昵称'
					this.$refs.uNotify.show(tipData)
					return false
				}
				data.user_sex = data.user_sex=='男生'?1:2
				this.showSub = true
				api.getRequst(data,'/api/My/updateInfo').then((res)=>{
					this.showSub = false
					if(res.code==1){
						this.$refs.uToast.show({
							message:'修改成功',
						})
					}
				})
			}
		},
		onLoad() {
			this.getData()
		}
	}
</script>

<style lang="scss">
.showCont{
	min-height: 100vh;
	background-color: #f8f8f8;
	box-sizing: border-box;
	padding-bottom: 30rpx;
	.bannerCont{
		padding-top: 120rpx;
		background-image: linear-gradient(to bottom,#3f55cc,#f8f8f8);
		image{
			width: 100%;
		}
	}
	.formCont{
		background-color: #fff;
		border-radius: 30rpx;
		padding: 40rpx 30rpx 60rpx;
		width: 92%;
		margin: 30rpx auto 30rpx;
		box-sizing: border-box;
		.formTitle{
			font-size: 32rpx;
			margin-bottom: 30rpx;
			font-weight: bold;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}
		.headImgCont{
			display: flex;
			justify-content: center;
		}
		.formItem{
			margin-top: 30rpx;
			display: flex;
			align-items: center;
			background-color: #f8f8f8;
			padding: 25rpx 50rpx;
			box-sizing: border-box;
			border-radius: 50rpx;
			.inputName {
			  width: 140rpx;
			  position: relative;
			  font-size: 28rpx;
			  .mustIcon {
				font-size: 28rpx;
				top: 0;
				left: -16rpx;
				position: absolute;
				color: #ff5757;
			  }
			}
			.inputOut {
				flex: 1;
				width: 3rem;
				position: relative;
				.inputMask {
					width: 100%;
					height: 100%;
					position: absolute;
					left: 0;
					top: 0;
					z-index: 2;
				  }
				  input{
					width: 100%;
					border: none;
					background: none;
					outline: none;
					position: relative;
					z-index: 1;
				  }
			}
			.inputValue{
				flex: 1;
				width: 100rpx;
			}
			.getCode{
				font-size: 24rpx;
				color: #3f55cc;
			}
			.disCode{
				color:#999;
			}
			.icon-gouxuan1,.icon-xiala{
				color: #3f55cc;
			}
		}
		.bookItem{
			background-color: #f8f8f8;
			border-radius: 10rpx;
			padding: 30rpx;
			box-sizing: border-box;
			margin-top: 30rpx;
			.bookTop{
				display: flex;
				justify-content: space-between;
				align-items: center;
				.bookName{
					display: flex;
					align-items: center;
					font-weight: bold;
					font-size: 26rpx;
					.iconfont{
						margin-right: 15rpx;
					}
				}
			}
		}
		.formDesItem{
			display: flex;
			margin-bottom: 20rpx;
			.desName{
				color: #333;
				width: 120rpx;
				text-align: right;
				margin-right: 30rpx;
			}
		}
		.formDesMoney{
			display: flex;
			justify-content: flex-end;
			padding-top: 30rpx;
			border-top: 1px dashed #ddd;
			margin-top: 30rpx;
			align-items: center;
			.redText{
				color: #ff5757;
				font-size: 40rpx;
			}
		}
		.formMustRead{
			text-indent: 60rpx;
			line-height: 40rpx;
		}
	}
	.linkCont{
		width:100%;
		padding: 0 4%;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		color: #666;
		.checkBox{
			width: 24rpx;
			height: 24rpx;
			font-size: 24rpx;
			border-radius: 4rpx;
			border: 1px solid #ddd;
			background-color: #fff;
			color: #fff;
			text-align: center;
			line-height: 24rpx;
			margin-right: 15rpx;
		}
		.isCheck{
			background-color: #3f55cc;
			border: 1px solid #3f55cc;
		}
		.linkText{
			color: #3f55cc;
		}
	}
	.noBootm{
		padding-bottom: 30rpx;
	}
	.hasTop{
		margin-top: -170rpx;
	}
	.saveBtn{
		width: 92%;
		margin: 30rpx auto 0;
		border-radius: 50rpx;
		background-image: linear-gradient(to right,#5f80db,#3f55cc);
		color: #fff;
		font-size: 24rpx;
		padding: 30rpx 0;
		text-align: center;
		z-index: 2;
	}
}
</style>
